
$().ready(function(){
	
    $baseUrl=$("#baseUrl").text();
    
    // Event handlers;
    $.address.change(function(event) {
    	check();
    });
    

	$("#tabMessageboard").live('click',function(){
		$.address.value('/messageboard'); 
	});
	
	$("#tabActivities").live('click',function(){
		$.address.value('/activities'); 
	});
	

	
	$("#post").live("click",function(e){
		console.log("here");
		
		$comment = $('#comment').val();
		$post_user_id = $('#post_user_id').val();
		$target_user_id = $('#target_user_id').val();
		
		if ($comment.length<6) {
			alert("表灌水！-_-|| (五个字以上)");
			return false;
		}
		
		$('#comment').addClass("processing");
	    $.post($baseUrl+'/user/postmessageajax',
					{'post_user_id':$post_user_id, 'comment':$comment, 'target_user_id':$target_user_id},
					function(data){
						$.address.value('/messageboard'); 
						$("#activities,#messageboard").remove();
						$("#logSection").append(data);
						$('#comment').removeClass("processing").val('');
					});
	    return false;
		
	});
   
    //check   
    function check(){
    	
    	$user_id= $('#profileUserId').text();
    	
    	
    if ($.address.value() == '/messageboard'){
    	
    	$("#activities,#messageboard").remove();

    	$("#tabActivities").removeClass("tabOn");
    	$("#tabMessageboard").addClass("tabOn");

    	$.ajax({
    		  url: $baseUrl+ '/user/findmessageboardajax',
    		  type: 'post',
    		  async: false,
    		  data: ({'user_id' : $user_id}),
    		  success: function(data) {
    		$("#logSection").append(data);
    		  }});  
    	
    	
    } else {

    	$("#activities,#messageboard").remove();
    	$("#tabActivities").addClass("tabOn");
    	$("#tabMessageboard").removeClass("tabOn");
    	
    	$.ajax({
    		  url: $baseUrl+ '/user/findactivitiesajax',
    		  type: 'post',
    		  async: false,
    		  data: ({'user_id' : $user_id}),
    		  success: function(data) {
    		$("#logSection").append(data);
    		  }});  
    }
    }
});